//
//  RHDataTypeCell.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2023/7/27.
//


#define item_count 4
#import "RHDataTypeCell.h"
#import "RHDataTypeItemCell.h"
@interface RHDataTypeCell()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@property(nonatomic,strong)UICollectionView *collectionView;

@property (nonatomic, strong) NSArray *AngleArr;
@end
@implementation RHDataTypeCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self setupUI];
    }
    return self;
}
-(void)setTypeModelArr:(NSArray *)typeModelArr
{
    _typeModelArr = typeModelArr;

    for (int i = 0;i < typeModelArr.count; i ++) {
        RHDeviceTypeModel *model = typeModelArr[i];
        QMUILabel *titleLab = [self.contentView viewWithTag:100 + 100*i];
        QMUILabel *contentLab = [self.contentView viewWithTag:100 + 100*i +1];
        titleLab.text = [NSString stringWithFormat:@"%ld",model.deviceNumber];
        contentLab.text = ValidNullDataToString(model.productTypeName, @"--");
    }
    
   
}
- (void)setupUI{
    self.backgroundColor = UIColor.clearColor;
    self.contentView.backgroundColor = UIColor.clearColor;
    
    
    UIView *bgView = [[UIView alloc]init];
    bgView.backgroundColor = UIColor.whiteColor;
    bgView.layer.cornerRadius = 8;
    bgView.layer.masksToBounds = YES;
    [self.contentView addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(100 + kNavHeight);
        make.left.mas_offset(15);
        make.right.mas_offset(-15);
        make.bottom.mas_offset(-15);
    }];
    
    QMUILabel *titleLab = [[QMUILabel alloc]init];
    titleLab.text = @"设备类型".rh_localized;
    titleLab.textColor = kCOLOR_HEX(@"#171A1D");
    titleLab.textAlignment = NSTextAlignmentRight;
    titleLab.font = kBOLDSYSTEMFONT(16);
    [bgView addSubview:titleLab];
 
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(15);
        make.left.mas_offset(15);
    }];
    
    UIView *line = kView;
    line.backgroundColor = kCOLOR_HEX_A(@"#7E868E",0.16);
    [bgView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_offset(0);
        make.top.equalTo(titleLab.mas_bottom).offset(15);
        make.height.offset(1);
    }];
    
    UIImageView *topIcon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"kwt_home_top_icon"]];
    topIcon.contentMode = UIViewContentModeScaleAspectFill;
    [self.contentView addSubview:topIcon];
    [topIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_offset(0);
        make.width.offset(kScaleW(175));
        make.height.offset(kScaleW(135));
        make.top.mas_offset(kNavHeight);
    }];
    
    NSArray *iconArr = @[@"dev_allinone_icon",@"dev_me_dc_icon",@"dev_bat_icon",@"dev_me_ac_icon"];
    NSArray *tagArr = @[@(2),@(4),@(1),@(3)];
    __block CGFloat itemWidth = (kUI_WINDOW_W -30-30)/2;
    __block UIView *lastView;
    [iconArr enumerateObjectsUsingBlock:^(NSString*  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        UIView *itemView = [self itemViewWithIndex:[tagArr[idx]integerValue] title:@"--" image:obj];
        [bgView addSubview:itemView];
        if (idx == 0) {
            [itemView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(line.mas_bottom).offset(10);
                make.left.mas_offset(10);
                make.width.offset(itemWidth);
                make.height.offset(60);
            }];
        }else{
            if (idx%2==0) {
                [itemView mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.mas_offset(10);
                    make.top.equalTo(lastView.mas_bottom).offset(10);
                    make.width.height.equalTo(lastView);
                }];
            }else{
                [itemView mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.equalTo(lastView.mas_right).offset(10);
                    make.top.width.height.equalTo(lastView);
                }];
            }
        }
        lastView = itemView;
    }];
    [lastView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_offset(-10);
    }];
}


-(UIView*)itemViewWithIndex:(NSInteger)idx title:(NSString*)title image:(NSString*)imageStr
{
    UIView *bgView = kView;
    bgView.backgroundColor = kCOLOR_HEX(@"#F3F7FF");
    bgView.layer.cornerRadius = 8;
    bgView.layer.masksToBounds = YES;
    UIImageView *img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:imageStr]];
    [bgView addSubview:img];
    [img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(20);
        make.left.mas_offset(15);
        make.top.mas_offset(12);
    }];
    
    QMUILabel *titleLab = [[QMUILabel alloc]init];
    titleLab.textAlignment = NSTextAlignmentLeft;
    titleLab.numberOfLines = 0;
    titleLab.text = title;
    titleLab.tag = 100 * idx;
    titleLab.textColor = [UIColor colorWithHexString:@"#171A1D" alpha:1];
    titleLab.font = [UIFont systemFontOfSize:12];
    [bgView addSubview:titleLab];
    
    QMUILabel *contentLab = [[QMUILabel alloc]init];
    contentLab.textAlignment = NSTextAlignmentLeft;
    contentLab.tag = 100 * idx +1;
    contentLab.text = @"--";
    contentLab.textColor = [UIColor colorWithHexString:@"#132B88" alpha:0.6];
    contentLab.font = [UIFont boldSystemFontOfSize:12];
    [bgView addSubview:contentLab];
    
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(img.mas_right).offset(8);
        make.right.mas_offset(-3);
        make.centerY.equalTo(img.mas_centerY).offset(-3);
    }];
    
    [contentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(titleLab);
        make.top.equalTo(titleLab.mas_bottom).offset(5);
    }];
    return bgView;
}
@end
